package com.example.demo.config;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //WebMvcConfigurer.super.addInterceptors(registry);
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")  //拦截所有,一定要加上/ ， 不加不会生效
                .excludePathPatterns("/login.html")  // 不拦截注册和登陆静态页面
                .excludePathPatterns("/reg.html")
                .excludePathPatterns("/blog_list.html")
                .excludePathPatterns("/blog_content.html")
                .excludePathPatterns("/blog_add.html")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/editor.md/**")  //编译器中的所有也是不拦截的
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/img/**")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/islogin")
                .excludePathPatterns("/user/reg")   // 也不拦截 注册和登录 接口
                .excludePathPatterns("/art/getdetail") // 如果页面显示正常，但是没有数据，可能就是拦截器拦截掉了接口
                .excludePathPatterns("/art/addrcount")
                .excludePathPatterns("/art/getlistbypage")
                .excludePathPatterns("/art/mylist")
                .excludePathPatterns("/art/getcount")
        ;
    }
}
